﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using System;
using System.Text;
using System.IO;
namespace Azuo_Tool
{
    public class Array_Save
    {
        public static void save_vec2(Vector2[] input, string name)
        {
            string path = Application.streamingAssetsPath + @"/JsonData/" + name + ".txt";
            string contact = "";
            for (int i = 0; i < input.Length; i++)
            {
                string line = input[i].x + "," + input[i].y + "\n";
                contact += line;
            }

            File.WriteAllText(path, contact);

            Debug.Log("complic write" + path);
        }

        public static Vector2[] load_vec2(string name)
        {
            string path = Application.streamingAssetsPath + @"/JsonData/" + name + ".txt";

            if (File.Exists(path))
            {
                string[] contante = File.ReadAllLines(path);
                Vector2[] array = new Vector2[contante.Length];
                for (int i = 0; i < contante.Length; i++)
                {
                    string line = contante[i];
                    string[] xy = contante[i].Split(',');
                    array[i] = new Vector2(Convert.ToSingle(xy[0]), Convert.ToSingle(xy[1]));
                }
                return array;
            }
            return null;
        }

        public static void Save_Img(string name, Texture2D img)
        {
            if (img == null) return;
            string path = Application.dataPath + @"/img/" + name + ".jpg";
            byte[] bytes = img.EncodeToJPG();
            File.WriteAllBytes(path, bytes);
        }
    }
}

